package com.liuhengjia.langchain4japply.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 向量数据库配置类
 */
@Configuration
@ConfigurationProperties(prefix = "pgvector")
@Data
public class PgVectorConfig {
    private String host;
    private int port;
    private String database;
    private String user;
    private String password;
    private String table;

    /**
     * PgVector 向量数据库
     *
     * @return EmbeddingStore<TextSegment>
     */
    @Bean
    public EmbeddingStore<TextSegment> pgVectorEmbeddingStore() {
        return PgVectorEmbeddingStore.builder()
                .dropTableFirst(true)
                .createTable(true)
                .host(host)
                .port(port)
                .database(database)
                .user(user)
                .password(password)
                .table(table)
                .dimension(384)
                .build();
    }
}